#include <stdio.h>
#include "include/bitree.h"
#include "include/rbtree.h"

int a[] = { 56, 34, 54, 47, 78, 91, 24, 87, 74, 69, 43, 63, 58, 38, 25, 49, 23, 12, 8, 76, 85, 102, 99, 29 };

int test_bitree()
{
    bitree_t root = NULL;
    int num = sizeof(a) / sizeof(int);
	int i = 0;
    for (i = 0; i < num; i++) {
		bitree_insert(&root, a[i]);
	}
    bitree_in_order_print(root);
    printf("\n");
    bitree_pre_order_print(root);
    printf("\n");
    bitree_post_order_print(root);
    printf("\n");

    bitree_node_t *min = get_min_node(root);
    printf("min node: %d\n", min->data);
    bitree_node_t *max = get_max_node(root);
    printf("max node: %d\n", max->data);
    return 0;
}

int test_rbtree()
{
    //int a[] = {50, 77, 65};
    int num = sizeof(a)/sizeof(int);
    rbtree_t root = NULL;
    for (int i=0; i<8; i++)
    {
        //printf("insert: %d => ", a[i]);
        rbtree_insert(&root, a[i]);
        //rbtree_inorder_print(root);
        //printf("\n");
    }
    rbtree_inorder_print(root);
    printf("\n");
    // for (int i=0; i<8; i++)
    // {
    //     printf("delete: %d => ", a[i]);
    //     rbtree_delete(&root, a[i]);
    //     rbtree_inorder_print(root);
    //     printf("\n");
    // }
    rbtree_delete(&root, 54);
    rbtree_inorder_print(root);
    printf("\n");
}

int main()
{
    // test_bitree();
    test_rbtree();
    return 0;
}